#include<bits/stdc++.h>
using namespace std;
#define max 0.05
int main(){
	double a[10000]={0},b[10000]={0},c[10000]={0};
	int n,i,j,numa=0,numc=0;
	cin>>n;
	int expn,coef,maxa=0,maxb=0;
	for(i=0;i<n;i++){
		cin>>expn>>coef;
		a[expn]=coef;
		if(expn>maxa) maxa=expn;
	}
	cin>>n;
	for(i=0;i<n;i++){
		cin>>expn>>coef;
		b[expn]=coef;
		if(expn>maxb) maxb=expn;
	}
	for(i=maxa;i>=maxb;i--){
		c[i-maxb]=a[i]/b[maxb];
		for(j=maxb;j>=0;j--){
			a[i-maxb+j]-=c[i-maxb]*b[j];
		}
	}
	for(i=maxa;i>=0;i--){
		if(fabs(a[i])<max) a[i]=0;
		else numa++;
	}
	for(i=maxa;i>=0;i--){
		if(fabs(c[i])<max) c[i]=0;
		else numc++;
	}
	if(numc==0) printf("0 0 0.0");
	else {
		printf("%d",numc);
		for(i=maxa;i>=0;i--){
			if(c[i])printf(" %d %.1f",i,c[i]);
		}
	}
	printf("\n");
	if(numa==0) printf("0 0 0.0");
	else {
		printf("%d",numa);
		for(i=maxa;i>=0;i--){
			if(a[i]) printf(" %d %.1f",i,a[i]);
		}
	}
	return 0;
}
